import { Logger } from "../utils/log"
import { _decorator } from 'cc'
const { ccclass, uniquelyReferenced } = _decorator

@uniquelyReferenced
@ccclass('RootStore')
export class RootStore {
  private static _store: RootStore;
  #log = new Logger('RootStore')
  private constructor() {
    this.#log.debug('RootStore 实例化')
  }

  public static get instance(): RootStore {
    if(!this._store) {
      this._store = new RootStore()
    }

    return this._store
  }

  chapter: LDChapter.Chapter

  currentFrameId:number

  get currentFrame(): LDChapter.Frame | undefined {
    return this.chapter?.frames.map[this.currentFrameId.toString()]
  }

  getResource(resourceId: number): LDChapter.Resource {
    return this.chapter?.resources[resourceId]
  }

  getRole(roleId: number): LDChapter.Role {
    return this.chapter?.roles[roleId]
  }
}
